/*-----------------------------------------------------------------------------------
 *
 * 프로그램명	: ProductDAO.java
 * Version		: 1.0
 * 작성일 		: 2006-08-16
 * 작성자		:
 * 수정일 		:
 * 수정자		:
 * 설명		 	:
 * 기능		 	:
 *
 * Copyright (c) 2000 by H&H  All Rights Reserved.
 *
-------------------------------------------------------------------------------------*/
package com.joinhawaii.admin.product;

import java.io.*;

import java.util.*;
import java.sql.*;

import com.zll.framework.conf.Configuration;
import com.zll.framework.db.DBManager;
import com.zll.framework.model.HashBox;
import com.zll.framework.model.HashList;
import com.zll.framework.util.StringUtil;



public class ProductDAO
{
	/*할인호텔*/
	public HashList selectHotelList(HashMap infos) throws Exception
	{
        return DBManager.executeQuery("/hotel.xml", "select_hotel_list", infos);
	}

	public String selectMinPriceList(String hotel_id) throws Exception {
		HashMap param = new HashMap();
		param.put("hotel_id", hotel_id);
        return DBManager.executeQuery("/hotel.xml", "select_hotel_min_sales_price", param).get("min_sales_price", 0);
	}

	public HashList selectHotelRoomList(HashMap infos) throws Exception
	{
        return DBManager.executeQuery("/hotel.xml", "select_hotel_room_list", infos);
	}

	public HashList selectRoomPriceList(HashMap infos) throws Exception
	{
        return DBManager.executeQuery("/hotel.xml", "select_room_price_list", infos);
	}

	public String selectRoomPriceFromDate(String room_id) throws Exception
	{
		HashMap infos = new HashMap();
		infos.put("room_id", room_id);
		return DBManager.executeQuery("/hotel.xml", "select_room_price_from_date", infos).get("from_date",0);
	}

	/*렌터카*/
	public HashList selectCarList(HashMap infos) throws Exception
	{
		StringUtil.setPaging("/car.xml", "select_car_total", infos);
        return DBManager.executeQuery("/car.xml", "select_car_list", infos);
	}


	/*선택관광*/
	public HashList selectEnjoyList(HashMap infos) throws Exception
	{
        return DBManager.executeQuery("/enjoy.xml", "select_enjoy_list", infos);
	}

	public HashList selectEnjoyPriceList(HashMap infos) throws Exception
	{
        return DBManager.executeQuery("/enjoy.xml", "select_enjoy_price_list", infos);
	}


	/*할인패키지*/
	public HashList selectPackageList(HashMap infos) throws Exception
	{
        return DBManager.executeQuery("/package.xml", "select_package_list", infos);
	}

	public HashList selectPackageSchedule(HashMap infos) throws Exception
	{
        return DBManager.executeQuery("/package.xml", "select_package_schedule_list", infos);
	}

	public HashList selectPackageHotel(HashMap infos) throws Exception
	{
		return DBManager.executeQuery("/package.xml", "select_package_hotel", infos);
	}
	public HashList selectPackageEnjoy(HashMap infos) throws Exception
	{
		return DBManager.executeQuery("/package.xml", "select_package_enjoy", infos);
	}
	public HashList selectPackageCar(HashMap infos) throws Exception
	{
		return DBManager.executeQuery("/package.xml", "select_package_car", infos);
	}




	/*할인항공*/
	public HashList selectAirList(HashMap infos) throws Exception
	{
		StringUtil.setPaging("/air.xml", "select_air_total", infos);
        return DBManager.executeQuery("/air.xml", "select_air_list", infos);
	}

	/*주내선*/
	public HashList selectFlyList(HashMap infos) throws Exception
	{
        return DBManager.executeQuery("/fly.xml", "select_fly_list", infos);
	}

	/*골프*/
	public HashList selectGolfList(HashMap infos) throws Exception
	{
		return DBManager.executeQuery("/golf.xml", "select_golf_list", infos);
	}



	/**
	 * 호텔 저장
	 *
	 * @param	infos
	 * @return	boolean
	 */
	public void saveHotel(HashBox box) throws Exception
    {
		Connection conn = null;

        try
		{
			conn = DBManager.getConnection();

			HashMap map = box.getParam();

	    	if ("C".equals(map.get("job_type"))) {
	    		DBManager.executeUpdate("/hotel.xml", "insert_hotel", map, conn);
	       	} else if ("U".equals(map.get("job_type")))	{
	       		DBManager.executeUpdate("/hotel.xml", "update_hotel", map, conn);
	       	} else if ("D".equals(map.get("job_type"))) {
	       		DBManager.executeUpdate("/hotel.xml", "delete_hotel", map, conn);
	       		//DBManager.executeUpdate("/hotel.xml", "delete_hotel_price_all", map, conn);
	        }

			conn.commit();
	    }
	    catch(Exception e)
	    {
	    	DBManager.rollback(conn);
	    	throw e;
		}
	    finally
	    {
	    	DBManager.closeConnection(conn);
		}
    }
	/**
	 * 호텔 저장
	 *
	 * @param	infos
	 * @return	boolean
	 */
	public void saveHotelList(HashBox box) throws Exception
    {
		Connection conn = null;

        try
		{
			conn = DBManager.getConnection();

			ArrayList dataList = (ArrayList)box.getList("list");

			for (int i = 0; i < dataList.size(); i++)
		    {
				HashMap map = (HashMap)dataList.get(i);

	    		DBManager.executeUpdate("/hotel.xml", "update_hotel_list", map, conn);
	        }

			conn.commit();
	    }
	    catch(Exception e)
	    {
	    	DBManager.rollback(conn);
	    	throw e;
		}
	    finally
	    {
	    	DBManager.closeConnection(conn);
		}
    }
	/**
	 * 호텔 객실 저장
	 *
	 * @param	infos
	 * @return	boolean
	 */
	public void saveHotelRoom(HashBox box) throws Exception
    {
		Connection conn = null;

        try
		{
			conn = DBManager.getConnection();

			ArrayList dataList = (ArrayList)box.getList("list");

		    for (int i = 0; i < dataList.size(); i++)
		    {
				HashMap map = (HashMap)dataList.get(i);

				if ("C".equals(map.get("job_type"))) {
					DBManager.executeUpdate("/hotel.xml", "insert_room", map, conn);
		       	} else if ("U".equals(map.get("job_type"))) {
		       		DBManager.executeUpdate("/hotel.xml", "update_room", map, conn);
		       	} else if ("D".equals(map.get("job_type"))) {
		       		DBManager.executeUpdate("/hotel.xml", "delete_room", map, conn);
		        }
			}

			conn.commit();
	    }
	    catch(Exception e)
	    {
	    	DBManager.rollback(conn);
	    	throw e;
		}
	    finally
	    {
	    	DBManager.closeConnection(conn);
		}
    }


	/**
	 * 호텔 객실 가격 저장
	 *
	 * @param	infos
	 * @return	boolean
	 */
	public void saveHotelPrice(HashBox box) throws Exception
    {
		Connection conn = null;

        try
		{
			conn = DBManager.getConnection();

			ArrayList dataList = (ArrayList)box.getList("list");

		    for (int i = 0; i < dataList.size(); i++)
		    {
				HashMap map = (HashMap)dataList.get(i);

				if ("C".equals(map.get("job_type"))) {
					DBManager.executeUpdate("/hotel.xml", "insert_room_price", map, conn);
		       	} else if ("U".equals(map.get("job_type"))) {
		       		DBManager.executeUpdate("/hotel.xml", "update_room_price", map, conn);
		       	} else if ("D".equals(map.get("job_type"))) {
		       		DBManager.executeUpdate("/hotel.xml", "delete_room_price", map, conn);
		        }
			}

			conn.commit();
	    }
	    catch(Exception e)
	    {
	    	DBManager.rollback(conn);
	    	throw e;
		}
	    finally
	    {
	    	DBManager.closeConnection(conn);
		}
    }

	/**
	 * 패키지 저장
	 *
	 * @param	infos
	 * @return	boolean
	 */
	public void savePackage(HashBox box) throws Exception
    {
		Connection conn = null;

        try
		{
			conn = DBManager.getConnection();

			HashMap map = box.getParam();

	    	if ("C".equals(map.get("job_type"))) {
	    		DBManager.executeUpdate("/package.xml", "insert_package", map, conn);
	       	} else if ("U".equals(map.get("job_type")))	{
	       		DBManager.executeUpdate("/package.xml", "update_package", map, conn);
	       	} else if ("D".equals(map.get("job_type"))) {
	       		DBManager.executeUpdate("/package.xml", "delete_package", map, conn);
	        }

			conn.commit();
	    }
	    catch(Exception e)
	    {
	    	DBManager.rollback(conn);
	    	throw e;
		}
	    finally
	    {
	    	DBManager.closeConnection(conn);
		}
    }


	/**
	 * 패키지 목록 저장
	 *
	 * @param	infos
	 * @return	boolean
	 */
	public void savePackageList(HashBox box) throws Exception
    {
		Connection conn = null;

        try
		{
			conn = DBManager.getConnection();

			ArrayList dataList = (ArrayList)box.getList("list");

			for (int i = 0; i < dataList.size(); i++)
		    {
				HashMap map = (HashMap)dataList.get(i);

	    		DBManager.executeUpdate("/package.xml", "update_package_list", map, conn);
	        }

			conn.commit();
	    }
	    catch(Exception e)
	    {
	    	DBManager.rollback(conn);
	    	throw e;
		}
	    finally
	    {
	    	DBManager.closeConnection(conn);
		}
    }

	/**
	 * 패키지 상세일정 저장
	 *
	 * @param	infos
	 * @return	boolean
	 */
	public void savePackageSchedule(HashBox box) throws Exception
    {
		Connection conn = null;

        try
		{
			conn = DBManager.getConnection();

			HashMap map = box.getParam();

	    	DBManager.executeUpdate("/package.xml", "update_package_schedule", map, conn);
	       	

/*
			HashList list = box.getList("list");

			DBManager.executeUpdate("/package.xml", "delete_all_package_schedule", box.getParam(), conn);

			for (int i = 0; i < list.size(); i++) {
				if (!"".equals(list.get("detail_schedule",i))) {
					HashMap infos = (HashMap)list.get(i);
					DBManager.executeUpdate("/package.xml", "insert_package_schedule", infos, conn);
				}
			}
		*/

			conn.commit();
	    }
	    catch(Exception e)
	    {
	    	DBManager.rollback(conn);
	    	throw e;
		}
	    finally
	    {
	    	DBManager.closeConnection(conn);
		}
    }


	/**
	 * 패키지 상품 저장
	 *
	 * @param	infos
	 * @return	boolean
	 */
	public void savePackageProduct(HashBox box) throws Exception
    {
		Connection conn = null;

        try
		{
			conn = DBManager.getConnection();

			HashMap map = box.getParam();
			DBManager.executeUpdate("/package.xml", "update_package_product", map, conn);

			HashList hotel = box.getList("hotel");
       		DBManager.executeUpdate("/package.xml", "delete_package_hotel_all", map, conn);
			for (int i = 0; i < hotel.size(); i++) {
				if (!"".equals(hotel.get("hotel_id",i))) {
					HashMap infos = (HashMap)hotel.get(i);
					infos.put("package_id", map.get("package_id"));
					infos.put("package_seq", String.valueOf(i+1));
					DBManager.executeUpdate("/package.xml", "insert_package_hotel", infos, conn);
				}
			}

			//선택관광
			HashList enjoy = box.getList("enjoy");
       		DBManager.executeUpdate("/package.xml", "delete_package_enjoy_all", map, conn);
			for (int i = 0; i < enjoy.size(); i++) {
				if (!"".equals(enjoy.get("enjoy_id",i))) {
					HashMap infos = (HashMap)enjoy.get(i);
					infos.put("package_id", map.get("package_id"));
					infos.put("package_seq", String.valueOf(i+1));
					DBManager.executeUpdate("/package.xml", "insert_package_enjoy", infos, conn);
				}
			}

			//렌터카
			HashList car = box.getList("car");
       		DBManager.executeUpdate("/package.xml", "delete_package_car_all", map, conn);
			for (int i = 0; i < car.size(); i++) {
				if (!"".equals(car.get("car_id",i))) {
					HashMap infos = (HashMap)car.get(i);
					infos.put("package_id", map.get("package_id"));
					infos.put("package_seq", String.valueOf(i+1));
					DBManager.executeUpdate("/package.xml", "insert_package_car", infos, conn);
				}
			}

			conn.commit();
	    }
	    catch(Exception e)
	    {
	    	DBManager.rollback(conn);
	    	throw e;
		}
	    finally
	    {
	    	DBManager.closeConnection(conn);
		}
    }


	/**
	 * 선택관광 저장
	 *
	 * @param	infos
	 * @return	boolean
	 */
	public void saveEnjoy(HashBox box) throws Exception
    {
		Connection conn = null;

        try
		{
			conn = DBManager.getConnection();

			HashMap map = box.getParam();

	    	if ("C".equals(map.get("job_type"))) {
	    		DBManager.executeUpdate("/enjoy.xml", "insert_enjoy", map, conn);
	       	} else if ("U".equals(map.get("job_type")))	{
	       		DBManager.executeUpdate("/enjoy.xml", "update_enjoy", map, conn);
	       	} else if ("D".equals(map.get("job_type"))) {
	       		DBManager.executeUpdate("/enjoy.xml", "delete_enjoy", map, conn);
	       		DBManager.executeUpdate("/enjoy.xml", "delete_enjoy_price_all", map, conn);
	        }

			conn.commit();
	    }
	    catch(Exception e)
	    {
	    	DBManager.rollback(conn);
	    	throw e;
		}
	    finally
	    {
	    	DBManager.closeConnection(conn);
		}
    }
	/**
	 * 선택관광 목록 저장
	 *
	 * @param	infos
	 * @return	boolean
	 */
	public void saveEnjoyList(HashBox box) throws Exception
    {
		Connection conn = null;

        try
		{
			conn = DBManager.getConnection();

			ArrayList dataList = (ArrayList)box.getList("list");

			for (int i = 0; i < dataList.size(); i++)
		    {
				HashMap map = (HashMap)dataList.get(i);

	    		DBManager.executeUpdate("/enjoy.xml", "update_enjoy_list", map, conn);
	        }

			conn.commit();
	    }
	    catch(Exception e)
	    {
	    	DBManager.rollback(conn);
	    	throw e;
		}
	    finally
	    {
	    	DBManager.closeConnection(conn);
		}
    }
	/**
	 * 선택관광 가격 저장
	 *
	 * @param	infos
	 * @return	boolean
	 */
	public void saveEnjoyPrice(HashBox box) throws Exception
    {
		Connection conn = null;

        try
		{
			conn = DBManager.getConnection();

			ArrayList dataList = (ArrayList)box.getList("list");

		    for (int i = 0; i < dataList.size(); i++)
		    {
				HashMap map = (HashMap)dataList.get(i);

				if ("C".equals(map.get("job_type"))) {
					map.put("price_id", DBManager.executeQuery("/enjoy.xml", "select_enjoy_price_id", map, conn).get("price_id",0));
		    		DBManager.executeUpdate("/enjoy.xml", "insert_enjoy_price", map, conn);
		       	} else if ("U".equals(map.get("job_type"))) {
		       		DBManager.executeUpdate("/enjoy.xml", "update_enjoy_price", map, conn);
		       	} else if ("D".equals(map.get("job_type"))) {
		       		DBManager.executeUpdate("/enjoy.xml", "delete_enjoy_price", map, conn);
		        }
			}

			conn.commit();
	    }
	    catch(Exception e)
	    {
	    	DBManager.rollback(conn);
	    	throw e;
		}
	    finally
	    {
	    	DBManager.closeConnection(conn);
		}
    }




	/**
	 * 할인항공 저장
	 *
	 * @param	infos
	 * @return	boolean
	 */
	public void saveAir(HashBox box) throws Exception
    {
		Connection conn = null;

        try
		{
			conn = DBManager.getConnection();

			HashMap map = box.getParam();

	    	if ("C".equals(map.get("job_type"))) {
	    		DBManager.executeUpdate("/air.xml", "insert_air", map, conn);
	       	} else if ("U".equals(map.get("job_type")))	{
	       		DBManager.executeUpdate("/air.xml", "update_air", map, conn);
	       	} else if ("D".equals(map.get("job_type"))) {
	       		DBManager.executeUpdate("/air.xml", "delete_air", map, conn);
	        }

			conn.commit();
	    }
	    catch(Exception e)
	    {
	    	DBManager.rollback(conn);
	    	throw e;
		}
	    finally
	    {
	    	DBManager.closeConnection(conn);
		}
    }



	/**
	 * 주내선 저장
	 *
	 * @param	infos
	 * @return	boolean
	 */
	public void saveFly(HashBox box) throws Exception
    {
		Connection conn = null;

        try
		{
			conn = DBManager.getConnection();

			HashMap map = box.getParam();

	    	if ("C".equals(map.get("job_type"))) {
	    		DBManager.executeUpdate("/fly.xml", "insert_fly", map, conn);
	       	} else if ("U".equals(map.get("job_type")))	{
	       		DBManager.executeUpdate("/fly.xml", "update_fly", map, conn);
	       	} else if ("D".equals(map.get("job_type"))) {
	       		DBManager.executeUpdate("/fly.xml", "delete_fly", map, conn);
	        }

			conn.commit();
	    }
	    catch(Exception e)
	    {
	    	DBManager.rollback(conn);
	    	throw e;
		}
	    finally
	    {
	    	DBManager.closeConnection(conn);
		}
    }


	/**
	 * 렌터카 저장
	 *
	 * @param	infos
	 * @return	boolean
	 */
	public void saveCar(HashBox box) throws Exception
    {
		Connection conn = null;

        try
		{
			conn = DBManager.getConnection();

			HashMap map = box.getParam();

	    	if ("C".equals(map.get("job_type"))) {
	    		DBManager.executeUpdate("/car.xml", "insert_car", map, conn);
	       	} else if ("U".equals(map.get("job_type")))	{
	       		DBManager.executeUpdate("/car.xml", "update_car", map, conn);
	       	} else if ("D".equals(map.get("job_type"))) {
	       		DBManager.executeUpdate("/car.xml", "delete_car", map, conn);
	        }

			conn.commit();
	    }
	    catch(Exception e)
	    {
	    	DBManager.rollback(conn);
	    	throw e;
		}
	    finally
	    {
	    	DBManager.closeConnection(conn);
		}
    }


	/**
	 * 렌터카 목록 저장
	 *
	 * @param	infos
	 * @return	boolean
	 */
	public void saveCarList(HashBox box) throws Exception
    {
		Connection conn = null;

        try
		{
			conn = DBManager.getConnection();

			ArrayList dataList = (ArrayList)box.getList("list");

			for (int i = 0; i < dataList.size(); i++)
		    {
				HashMap map = (HashMap)dataList.get(i);

	    		DBManager.executeUpdate("/car.xml", "update_car_list", map, conn);
	        }

			conn.commit();
	    }
	    catch(Exception e)
	    {
	    	DBManager.rollback(conn);
	    	throw e;
		}
	    finally
	    {
	    	DBManager.closeConnection(conn);
		}
    }

	/**
	 * 골프 저장
	 *
	 * @param	infos
	 * @return	boolean
	 */
	public void saveGolf(HashBox box) throws Exception
    {
		Connection conn = null;

        try
		{
			conn = DBManager.getConnection();

			HashMap map = box.getParam();

	    	if ("C".equals(map.get("job_type"))) {
	    		DBManager.executeUpdate("/golf.xml", "insert_golf", map, conn);
	       	} else if ("U".equals(map.get("job_type")))	{
	       		DBManager.executeUpdate("/golf.xml", "update_golf", map, conn);
	       	} else if ("D".equals(map.get("job_type"))) {
	       		DBManager.executeUpdate("/golf.xml", "delete_golf", map, conn);
	        }

			conn.commit();
	    }
	    catch(Exception e)
	    {
	    	DBManager.rollback(conn);
	    	throw e;
		}
	    finally
	    {
	    	DBManager.closeConnection(conn);
		}
    }

	/**
	 * 참고사진 저장
	 *
	 * @param	infos
	 * @return	boolean
	 */
	public void savePic(HashBox box) throws Exception
    {
		Connection conn = null;

        try
		{
			conn = DBManager.getConnection();

			HashMap map = box.getParam();

	    	DBManager.executeUpdate("/"+map.get("pic_name")+".xml", "update_pic", map, conn);

			conn.commit();
	    }
	    catch(Exception e)
	    {
	    	DBManager.rollback(conn);
	    	throw e;
		}
	    finally
	    {
	    	DBManager.closeConnection(conn);
		}
    }
}
